﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Data.Common;
using Mocola.BLL;
using Mocola.Model;

namespace Mocola.Net.Web.ajax
{
    public partial class UpdateDept : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                MembershipCreateStatus status = new MembershipCreateStatus();
                DbTransaction transaction = Databases.MocolaNet.BeginTransaction(IsolationLevel.ReadCommitted);

                try
                {
                    int ID = Convert.ToInt32(Request.QueryString["id"]);
                    string pName = Server.UrlDecode(Request.QueryString["name"]);

                    bool bUpdated = Databases.MocolaNet.Update(Moc_DepartmentsInfo.Moc_Departments)
                                     .AddColumn(Moc_DepartmentsInfo.Moc_Departments.Name, pName)
                                     .Where(Moc_DepartmentsInfo.Moc_Departments.ID == ID)
                                     .SetTransaction(transaction)
                                     .Execute() == 1;
                    if (bUpdated)
                    {
                        Response.Write("部门更新成功！");
                        status = MembershipCreateStatus.Success;
                    }
                    else
                    {
                        Response.Write("部门更新失败！");
                        status = MembershipCreateStatus.ProviderError;
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                    status = MembershipCreateStatus.ProviderError;
                }
                finally
                {
                    if (status == MembershipCreateStatus.Success)
                        transaction.Commit();
                    else
                        transaction.Rollback();
                    Databases.MocolaNet.CloseConnection(transaction);
                }
            }
        }
    }
}
